<?php 
class HtmlController extends AuthController{
	public function __init(){
		define('__TEMPLATE__',__ROOT__.'/Template/'.C('WEBSTYLE'));
	}

	public function createIndex(){
		if(IS_POST){
			$status=$this->createHtml('index.html','./','Template/'.C('WEBSTYLE').'/index.html');
			if($status){
				$this->success('生成静态完毕','createIndex');
			}else{
				$this->error('生成静态失败','createIndex');
			}
		}else{
			$this->display();
		}
	}

	public function createCategory(){
		if(IS_POST){
			$category=M('category')->all();
			foreach ($category as $cat) {
				$_REQUEST['cid']=$_GET['cid']=$cat['cid'];
				$htmlDir='hd/'.$cat['html_dir'].'/';
				$this->assign('cms',$cat);
				$this->createHtml('index.html',$htmlDir,'Template/'.C('WEBSTYLE').'/'.$cat['list_tpl']);
				for($page=1;$page<=Page::$staticTotalPage;$page++){
					$_GET['page']=$page;
					Page::$staticUrl=__ROOT__.$htmlDir."{$page}.html";
					$this->createHtml($page.'.html','hd/'.$cat['html_dir'].'/','Template/'.C('WEBSTYLE').'/'.$cat['list_tpl']);
				}
				copy($htmlDir.'index.html',$htmlDir.'1.html');
			}
			$this->success('生成静态完毕','createIndex');
		}else{
			$this->display();
		}
	}

	public function createContent(){
		if(IS_POST){
			$db=K('Content');
			$data=$db->all();
			// p($data);exit;
			foreach ($data as $d) {
				$this->assign('cms',$d);
				$search=array(
					'{y}','{m}','{d}','{aid}'
				);
				$date=getdate($d['addtime']);
				$replace=array(
					$date['year'],
					$date['mon'],
					$date['mday'],
					$d['aid']
				);
				$file='hd/'.$d['html_dir'].'/'.str_replace($search, $replace, $d['arc_html_rule']);
				// p($file);
				$this->createHtml(basename($file),dirname($file).'/','Template/'.C('WEBSTYLE').'/'.$d['content_tpl']);

			}
			$this->success('静态生成完毕','createContent');
		}else{
			$this->display();
		}
	}

}

?>